package db

import (
	db "hulk-api/databases"
	"log"
)

type Tables struct {
	Dbname string 			`json:"dbname"`
	Instance string			`json:"instance"`
	List []table			`json:"list"`
}

type table struct {
	Name string 		`json:"name"`
}

func (ts *Tables) Show() ( err error) {
	instance := db.Instance(ts.Instance)
	conn , err := instance.DbConn(ts.Dbname)
	if err != nil {
		log.Println(err)
		return
	}
	defer conn.Close()
	//row := conn.QueryRow("select * from test where id =2;")
	//result, err := conn.Exec("show tables")

	rows, err := conn.Query("show tables"  )
	defer rows.Close()
	//var tableList []table
	for rows.Next() {
		var t table
		rows.Scan(&t.Name)
		ts.List = append(ts.List, t)
	}
	if err = rows.Err(); err != nil {
		return
	}
	return
}
